<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="com.scott.user.form.User" %>
<%@ page import="com.scott.user.dao.UserDao" %>
<%@ page import="java.util.List" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> 
<%@ taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户列表页面</title>
		<style>
		
			*{
				font-size: 12px;
				font-family: "微软雅黑";
			}
			
			table{
				width:300px;
				text-align:center;
				border-collapse:collapse;
			}
			
			table tr td{
				border:1px solid #999;
			}
		
		</style>
		
		
	</head>
	
	<body>
	
		
		<font color="red">用户列表页面</font>
		
		teacherName:${requestScope.teacherName}
		
		<!-- bean用来创建bean 访问bean 访问bean的属性 -->
		<!-- logic 用来进行逻辑判断 集合迭代  和 流程控制 -->
		<!-- html 用来创建struts表单 -->
		<!-- tiles  用来创建tiles样式-->
		<!-- nested 建立在前面三个标签库的基础上 具有前三个标签的所有功能 而且允许嵌套使用 -->
		<!-- 循环遍历标签 logic:iterate -->
		
		<%
			//page范围的变量 list
			
			List<User> list =  new UserDao().getUsers();
			System.out.print(list.size());
			pageContext.setAttribute("list", list);
		
		%>
		
		
		<table>
			<tr>
				<td>id</td>
				<td>用户名</td>
				<td>密码</td>
				<td>删除</td>
				<td>修改</td>
			</tr>
			<logic:iterate id="user" name="list">
			
				<tr>
					<td>
						<bean:write name="user" property="id"/>
					</td>
					<td>
						<bean:write name="user" property="username"/>
					</td>
					<td>
						<bean:write name="user" property="password"/>
					</td>
					<td>
						<a href="#" class="delete" lang="${user.id}" >删除</a>
					</td>
					<td>
						<a href="#" class="update" lang="${user.id}" >修改</a>
					</td>
				</tr>
			</logic:iterate>
		
		</table>
		
		
		
		<!-- 用来显示错误提示 -->
		<div id="msg"></div>
		
		
		<br/><br/>
		<a href="main.jsp">返回主页面</a><br/>
	
	</body>
	
	<script type="text/javascript" src="js/jquery-1.8.2.min.js" ></script>
	<script type="text/javascript">
	
		$(function(){
			//1遍历所有带有.delete类样式的a标签
			$('.delete').each(function(index,element){
				//2 给每一个a标签按钮绑定单击删除事件
				$(this).click(function(){
					
					var id = this.lang;
					
					//发送ajax请求
					$.post("deleteUser.do",{
						'id':id,
						'password':''
						
					},function(data){	
						window.location.href='user-list.jsp';
						
					});
					
				});
				
			});
			
			
			//1遍历所有带有.update类样式的a标签
			$('.update').each(function(){
				//2 给每一个a标签按钮绑定单击删除事件
				$(this).click(function(){
					
					var id = this.lang;
					//跳转到user-update.jsp
					window.location.href='user-update.jsp?id='+id;
						
					
				});
				
			});
			
		});
		
	
	</script>
	
</html>